<?php

/**
 * A TournamentRegistration legegyszerűbb kezelése egy fake box. Mivel tök ugyanúgy működik és tök ugyanúgy
 * néz ki, mint a többi box.
 *
 * Ez egy spéci "cikklista"...
 *
 * @author poli
 */
class TournamentRegistrationBoxContentList extends BoxContentList {

	public function TournamentRegistrationBoxContentList($_parentTab) {
		$this->id = ConstHandler::get('TOURNAMENTREGISTRATION_BOXCONTENTLIST_FAKE_ID');
		$this->parentBoxTab = $_parentTab;
		$this->langcode = $_parentTab->langcode;
		$this->isDefault = true;

		$this->type = BOXCONTENTLIST_TYPE_FIXED;
		$this->sizeMin = null;
		$this->sizeMax = null;

		$this->reloadState();
	}

	/**
	 * Ezt felül kell írni, h tuti ne csináljon semmit. Amúgy az őse sem csinált volna
	 * semmit jelenleg - lévén ez egy fix lista - de azért tuti ami tuti!
	 */
	public function initArticleList($targetElementWeights) {
	}

	/**
	 * HTML generálása. Na, ez tök más mint az ősclassban...
	 * @return string
	 */
	public function generateHtml() {
		$tournamentId = FunctionLibrary::getGetValue('id');
		if (! is_null($tournamentId) && is_numeric($tournamentId)) {
			$tpl = BaseSitePage::loadTemplateFile("tournamentregistrations.tpl.html");

			$records = SiteDBHelper::getTournamentRegistrations($tournamentId, false);
			if (! empty($records)) {
				$ttypes = SiteDBHelper::getTournamentTypesOfTournament($tournamentId, TextHandler::getCurrentLangcode());
				$ttypes = TournamentHandler::getTournamentTypesForCombo($ttypes);
				$prevTType = -1;
				$counter = 0;
				foreach($records as $record) {
					if ($prevTType != $record['id_tournamenttype']) {
						if ($prevTType > 0) {
							$tpl->setVariable('registrationsHtml', $registrationHtml->toString());
							$tpl->setVariable('registered', TextHandler::getParsedText('comp_noofentry', array('no' => $counter)));
							$tpl->parseCurrentBlock();
						}
						$tpl->setCurrentBlock('tournamenttypes');
						$tpl->setVariable('tournamentType', $ttypes[$record['id_tournamenttype']]);
						$prevTType = $record['id_tournamenttype'];
						$registrationHtml = new StringBuffer();
						$counter = 0;
					}
					$regTpl = BaseSitePage::loadTemplateFile("tournamentregistration.tpl.html");

					$trClasses = ($counter++ % 2? array('neveztek_1'): array('neveztek_2'));

					$regTpl->setVariable("classes", implode($trClasses, " "));

					$regTpl->setVariable("serial", $counter);

					$players = implode(" - ", $record['players']);
					$regTpl->setVariable("players", $players);

					$registrationHtml->append($regTpl->get());
				}
				if ($prevTType > 0) {
					$tpl->setVariable('registrationsHtml', $registrationHtml->toString());
					$tpl->setVariable('registered', TextHandler::getParsedText('comp_noofentry', array('no' => $counter)));
					$tpl->parseCurrentBlock();
				}
				$html = $tpl->get();
			} else {
				$html = TextHandler::getParsedText('comp_noofentry', array('no' => '0'));
			}
		} else {
			$html = '';
		}

		return $html;
	}

}
?>